package util;

import java.util.HashMap;

public class MySpring {
    private static HashMap<String, Object> beanMap = new HashMap<>();

    //单例
    public static <T> T getBean(String name) {
        T t = (T) beanMap.get(name);
        if (t == null) {
            Class<?> aClass = null;
            try {
                aClass = Class.forName(name);
                t = (T) aClass.newInstance();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            }
            beanMap.put(name, t);
        }
        return t;
    }
}
